{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution(object):\n",
    "    def firstUniqChar(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        exist_char = {}\n",
    "        s = list(s)\n",
    "        for i in range(len(s)):\n",
    "            if s[i] in exist_char:\n",
    "                exist_char[s[i]] = None\n",
    "            else:\n",
    "                exist_char[s[i]] = i\n",
    "        \n",
    "        first = -1\n",
    "        for key, value in exist_char.items():\n",
    "            if value is not None:\n",
    "                if first < 0:\n",
    "                    first = value\n",
    "                elif first >=0 and value < first:\n",
    "                    first = value\n",
    "\n",
    "        return first if first >= 0 else -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = Solution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.firstUniqChar('lleetcode')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
